package com.example.login;


import com.example.mapper.UserMapper;
import com.example.module.User;
import com.example.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Resource
    @Lazy
    private UserService userService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        User user = userService.selectByName(username);
        if(Objects.isNull(user)){
            throw new RuntimeException("账户不存在");
        }

        return new UserDetailsImpl(user);
    }
}
